package com.googlecode.grima.service;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.googlecode.grima.base.GenericDao;
import com.googlecode.grima.base.GenericEntityService;
import com.googlecode.grima.base.GenericEntityServiceImpl;
import com.googlecode.grima.base.SearchTemplate;
import com.googlecode.grima.dao.DescriptiveItemDao;
import com.googlecode.grima.domain.DescriptiveItem;

@Service("descriptiveItemService")
public class DescriptiveItemService extends GenericEntityServiceImpl<DescriptiveItem, Long> implements GenericEntityService<DescriptiveItem, Long> {

	protected DescriptiveItemDao descriptiveItemDao;

	@Autowired
	public void setDescriptiveItemDao(DescriptiveItemDao descriptiveItemDao) {
		this.descriptiveItemDao = descriptiveItemDao;
	}

	@Override
	public GenericDao<DescriptiveItem, Long> getDao() {
		return descriptiveItemDao;
	}

	@Override
	public DescriptiveItem getNew() {
		return new DescriptiveItem();
	}

	@Override
	public DescriptiveItem getNewWithDefaults() {
		return getNew();
	}
	
	@Override
	@Transactional
	public void save(DescriptiveItem descriptiveItem) {
		super.save(descriptiveItem);
	}

	public List<DescriptiveItem> findByParameters(Long descriptive, String reference) {
		
    SearchTemplate searchTemplate = new SearchTemplate();
    
  	searchTemplate.addCriterion(Restrictions.eq("descriptive.id", descriptive));
  	searchTemplate.addCriterion(Restrictions.eq("reference", reference));

		return find(searchTemplate);
  }


}
